<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form class="verify-form" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="openid">
      <el-input v-model="dataForm.openid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="订阅状态" prop="subscribeStatus">
      <el-input v-model="dataForm.subscribeStatus" placeholder="订阅状态"></el-input>
    </el-form-item>
    <el-form-item label="订阅时间" prop="subscribeTime">
      <el-input v-model="dataForm.subscribeTime" placeholder="订阅时间"></el-input>
    </el-form-item>
    <el-form-item label="昵称" prop="nickname">
      <el-input v-model="dataForm.nickname" placeholder="昵称"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="gender">
      <el-input v-model="dataForm.gender" placeholder="性别"></el-input>
    </el-form-item>
    <el-form-item label="语言" prop="language">
      <el-input v-model="dataForm.language" placeholder="语言"></el-input>
    </el-form-item>
    <el-form-item label="国家" prop="country">
      <el-input v-model="dataForm.country" placeholder="国家"></el-input>
    </el-form-item>
    <el-form-item label="省" prop="province">
      <el-input v-model="dataForm.province" placeholder="省"></el-input>
    </el-form-item>
    <el-form-item label="市" prop="city">
      <el-input v-model="dataForm.city" placeholder="市"></el-input>
    </el-form-item>
    <el-form-item label="头像地址" prop="headimgUrl">
      <el-input v-model="dataForm.headimgUrl" placeholder="头像地址"></el-input>
    </el-form-item>
    <el-form-item label="粉丝来源" prop="fansSource">
      <el-input v-model="dataForm.fansSource" placeholder="粉丝来源"></el-input>
    </el-form-item>
    <el-form-item label="推广员id" prop="promoterId">
      <el-input v-model="dataForm.promoterId" placeholder="推广员id"></el-input>
    </el-form-item>
    <el-form-item label="粉丝联系方式" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="粉丝联系方式"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="微信积分" prop="integral">
      <el-input v-model="dataForm.integral" placeholder="微信积分"></el-input>
    </el-form-item>
    <el-form-item label="微信公众号ID" prop="wxAccountId">
      <el-input v-model="dataForm.wxAccountId" placeholder="微信公众号ID"></el-input>
    </el-form-item>
    <el-form-item label="微信公众号中文名称" prop="wxAccountName">
      <el-input v-model="dataForm.wxAccountName" placeholder="微信公众号中文名称"></el-input>
    </el-form-item>
    <el-form-item label="appid" prop="wxAccountAppid">
      <el-input v-model="dataForm.wxAccountAppid" placeholder="appid"></el-input>
    </el-form-item>
    <el-form-item label="粉丝状态(1-48小时内活跃粉丝,0-非48小时内活跃粉丝)" prop="status">
      <el-input v-model="dataForm.status" placeholder="粉丝状态(1-48小时内活跃粉丝,0-非48小时内活跃粉丝)"></el-input>
    </el-form-item>
    <el-form-item label="标签id" prop="labelId">
      <el-input v-model="dataForm.labelId" placeholder="标签id"></el-input>
    </el-form-item>
    <el-form-item label="关注时间" prop="joinTime">
      <el-input v-model="dataForm.joinTime" placeholder="关注时间"></el-input>
    </el-form-item>
    <el-form-item label="人员id/会员id" prop="personId">
      <el-input v-model="dataForm.personId" placeholder="人员id/会员id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getWxAccountFansObj, addWxAccountFansObj, putWxAccountFansObj} from '@/api/mp/wxaccountfans'

    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          openid: '',
          subscribeStatus: '',
          subscribeTime: '',
          nickname: '',
          gender: '',
          language: '',
          country: '',
          province: '',
          city: '',
          headimgUrl: '',
          fansSource: '',
          promoterId: '',
          phone: '',
          remark: '',
          integral: '',
          wxAccountId: '',
          wxAccountName: '',
          wxAccountAppid: '',
          status: '',
          labelId: '',
          joinTime: '',
          personId: '',
          createTime: '',
          updateTime: '',
          delFlag: '',
          tenantId: ''
        },
        dataRule: {
          openid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          subscribeStatus: [
            { required: true, message: '订阅状态不能为空', trigger: 'blur' }
          ],
          subscribeTime: [
            { required: true, message: '订阅时间不能为空', trigger: 'blur' }
          ],
          nickname: [
            { required: true, message: '昵称不能为空', trigger: 'blur' }
          ],
          gender: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          language: [
            { required: true, message: '语言不能为空', trigger: 'blur' }
          ],
          country: [
            { required: true, message: '国家不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '市不能为空', trigger: 'blur' }
          ],
          headimgUrl: [
            { required: true, message: '头像地址不能为空', trigger: 'blur' }
          ],
          fansSource: [
            { required: true, message: '粉丝来源不能为空', trigger: 'blur' }
          ],
          promoterId: [
            { required: true, message: '推广员id不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '粉丝联系方式不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          integral: [
            { required: true, message: '微信积分不能为空', trigger: 'blur' }
          ],
          wxAccountId: [
            { required: true, message: '微信公众号ID不能为空', trigger: 'blur' }
          ],
          wxAccountName: [
            { required: true, message: '微信公众号中文名称不能为空', trigger: 'blur' }
          ],
          wxAccountAppid: [
            { required: true, message: 'appid不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '粉丝状态(1-48小时内活跃粉丝,0-非48小时内活跃粉丝)不能为空', trigger: 'blur' }
          ],
          labelId: [
            { required: true, message: '标签id不能为空', trigger: 'blur' }
          ],
          joinTime: [
            { required: true, message: '关注时间不能为空', trigger: 'blur' }
          ],
          personId: [
            { required: true, message: '人员id/会员id不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          delFlag: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          tenantId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getWxAccountFansObj(this.dataForm.id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
                putWxAccountFansObj(this.dataForm).then(data => {
                    this.$message.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                });
            } else {
                addWxAccountFansObj(this.dataForm).then(data => {
                    this.$message.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                })
            }
          }
        })
      }
    }
  }
</script>
